//方法概念及使用
public class Test {
    //
    public static boolean isLeapYear(int year){
        if(0 == year && 0 != year % 100 || 0 == year % 400){
            return true;
        }else{
            return false;
        }
    }
    public static void func(){
        System.out.println("func()");
    }
   /* public static int add(int x,int y){
        return x+y;
    }*/

    //求阶乘
    public static int fac(int n){
        int i = 0;
        int ret = 1;
        for(i = 1 ; i <= n ; i ++){
            ret *= i;
        }
        return ret;
    }
    public static int facsum(int n){
        int sum = 0;
        for(int i = 1 ; i <= n ; i++){
            sum +=fac(i);
        }
        return sum;
    }

    //方法重载
    public static int add(int a,int b){
        return a+b;
    }
    public static double add(double a,double b){
        return a+b;
    }
    //方法名相同 参数列表不同 返回值不影响重载
    public static void main2(String[] args) {
        int a = 27;
        int b = 98;
        System.out.println(add(a,b));;
        double d1 = 12.5;
        double d2 = 2.7;
        System.out.println(add(d1,d2));
    }
    public static void main1(String[] args) {
       //方法的调用
        int year = 1990;
        boolean flg = isLeapYear(2026);
        System.out.println(flg);
        int sum = add(3,5);
        System.out.println(sum);
        func();
        System.out.println("");
        System.out.println(fac(5));
        System.out.println(fac(4));
        System.out.println(facsum(5));
    }

    //递归
    //按顺序打印数字的每一位
    public static void print(int num){
        if(num<10){
            System.out.println(num);
            return;
        }else{
            print(num/10);
            System.out.println(num%10);
        }

    }
    //递归求1+2+3+4+5+6+7+8+9+10
    public static int sum(int sum){
        if(sum == 1){
            return 1;
        }
        return sum+sum(sum-1);
    }
    public static void main(String[] args) {
        print(1234);
        System.out.println(sum(10));//55
    }

}
